home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / MediaMan 3 / MediaMan3Setup.msi / disk1.cab / MediaMan_Help.chm / js / xtree.js < prev   
Text File  |  2008-09-16  |  23KB  |  541 lines

  1. /*----------------------------------------------------------------------------\
  2. |                       Cross Browser Tree Widget 1.17                        |
  3. |-----------------------------------------------------------------------------|
  4. |                          Created by Emil A Eklund                           |
  5. |                  (http://webfx.eae.net/contact.html#emil)                   |
  6. |                      For WebFX (http://webfx.eae.net/)                      |
  7. |-----------------------------------------------------------------------------|
  8. | An object based tree widget,  emulating the one found in microsoft windows, |
  9. | with persistence using cookies. Works in IE 5+, Mozilla and konqueror 3.    |
  10. |-----------------------------------------------------------------------------|
  11. |                   Copyright (c) 1999 - 2002 Emil A Eklund                   |
  12. |-----------------------------------------------------------------------------|
  13. | This software is provided "as is", without warranty of any kind, express or |
  14. | implied, including  but not limited  to the warranties of  merchantability, |
  15. | fitness for a particular purpose and noninfringement. In no event shall the |
  16. | authors or  copyright  holders be  liable for any claim,  damages or  other |
  17. | liability, whether  in an  action of  contract, tort  or otherwise, arising |
  18. | from,  out of  or in  connection with  the software or  the  use  or  other |
  19. | dealings in the software.                                                   |
  20. | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
  21. | This  software is  available under the  three different licenses  mentioned |
  22. | below.  To use this software you must chose, and qualify, for one of those. |
  23. | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
  24. | The WebFX Non-Commercial License          http://webfx.eae.net/license.html |
  25. | Permits  anyone the right to use the  software in a  non-commercial context |
  26. | free of charge.                                                             |
  27. | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
  28. | The WebFX Commercial license           http://webfx.eae.net/commercial.html |
  29. | Permits the  license holder the right to use  the software in a  commercial |
  30. | context. Such license must be specifically obtained, however it's valid for |
  31. | any number of  implementations of the licensed software.                    |
  32. | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
  33. | GPL - The GNU General Public License    http://www.gnu.org/licenses/gpl.txt |
  34. | Permits anyone the right to use and modify the software without limitations |
  35. | as long as proper  credits are given  and the original  and modified source |
  36. | code are included. Requires  that the final product, software derivate from |
  37. | the original  source or any  software  utilizing a GPL  component, such  as |
  38. | this, is also licensed under the GPL license.                               |
  39. |-----------------------------------------------------------------------------|
  40. | Dependencies: xtree.css (To set up the CSS of the tree classes)             |
  41. |-----------------------------------------------------------------------------|
  42. | 2001-01-10 | Original Version Posted.                                       |
  43. | 2001-03-18 | Added getSelected and get/setBehavior  that can make it behave |
  44. |            | more like windows explorer, check usage for more information.  |
  45. | 2001-09-23 | Version 1.1 - New features included  keyboard  navigation (ie) |
  46. |            | and the ability  to add and  remove nodes dynamically and some |
  47. |            | other small tweaks and fixes.                                  |
  48. | 2002-01-27 | Version 1.11 - Bug fixes and improved mozilla support.         |
  49. | 2002-06-11 | Version 1.12 - Fixed a bug that prevented the indentation line |
  50. |            | from  updating correctly  under some  circumstances.  This bug |
  51. |            | happened when removing the last item in a subtree and items in |
  52. |            | siblings to the remove subtree where not correctly updated.    |
  53. | 2002-06-13 | Fixed a few minor bugs cased by the 1.12 bug-fix.              |
  54. | 2002-08-20 | Added usePersistence flag to allow disable of cookies.         |
  55. | 2002-10-23 | (1.14) Fixed a plus icon issue                                 |
  56. | 2002-10-29 | (1.15) Last changes broke more than they fixed. This version   |
  57. |            | is based on 1.13 and fixes the bugs 1.14 fixed withou breaking |
  58. |            | lots of other things.                                          |
  59. | 2003-02-15 | The  selected node can now be made visible even when  the tree |
  60. |            | control  loses focus.  It uses a new class  declaration in the |
  61. |            | css file '.webfx-tree-item a.selected-inactive', by default it |
  62. |            | puts a light-gray rectangle around the selected node.          |
  63. | 2003-03-16 | Adding target support after lots of lobbying...                |
  64. |-----------------------------------------------------------------------------|
  65. | Created 2000-12-11 | All changes are in the log above. | Updated 2003-03-16 |
  66. \----------------------------------------------------------------------------*/
  67.  
  68. var webFXTreeConfig = {
  69.     rootIcon        : 'images/foldericon.png',
  70.     openRootIcon    : 'images/openfoldericon.png',
  71.     folderIcon      : 'images/foldericon.png',
  72.     openFolderIcon  : 'images/openfoldericon.png',
  73.     fileIcon        : 'images/file.png',
  74.     iIcon           : 'images/I.png',
  75.     lIcon           : 'images/L.png',
  76.     lMinusIcon      : 'images/Lminus.png',
  77.     lPlusIcon       : 'images/Lplus.png',
  78.     tIcon           : 'images/T.png',
  79.     tMinusIcon      : 'images/Tminus.png',
  80.     tPlusIcon       : 'images/Tplus.png',
  81.     blankIcon       : 'images/blank.png',
  82.     defaultText     : 'Tree Item',
  83.     defaultAction   : 'javascript:void(0);',
  84.     defaultBehavior : 'classic',
  85.     usePersistence    : true
  86. };
  87.  
  88. var webFXTreeHandler = {
  89.     idCounter : 0,
  90.     idPrefix  : "webfx-tree-object-",
  91.     all       : {},
  92.     behavior  : null,
  93.     selected  : null,
  94.     onSelect  : null, /* should be part of tree, not handler */
  95.     getId     : function() { return this.idPrefix + this.idCounter++; },
  96.     toggle    : function (oItem) { this.all[oItem.id.replace('-plus','')].toggle(); },
  97.     select    : function (oItem) { this.all[oItem.id.replace('-icon','')].select(); },
  98.     focus     : function (oItem) { this.all[oItem.id.replace('-anchor','')].focus(); },
  99.     blur      : function (oItem) { this.all[oItem.id.replace('-anchor','')].blur(); },
  100.     keydown   : function (oItem, e) { return this.all[oItem.id].keydown(e.keyCode); },
  101.     cookies   : new WebFXCookie(),
  102.     insertHTMLBeforeEnd    :    function (oElement, sHTML) {
  103.         if (oElement.insertAdjacentHTML != null) {
  104.             oElement.insertAdjacentHTML("BeforeEnd", sHTML)
  105.             return;
  106.         }
  107.         var df;    // DocumentFragment
  108.         var r = oElement.ownerDocument.createRange();
  109.         r.selectNodeContents(oElement);
  110.         r.collapse(false);
  111.         df = r.createContextualFragment(sHTML);
  112.         oElement.appendChild(df);
  113.     }
  114. };
  115.  
  116. /*
  117.  * WebFXCookie class
  118.  */
  119.  
  120. function WebFXCookie() {
  121.     if (document.cookie.length) { this.cookies = ' ' + document.cookie; }
  122. }
  123.  
  124. WebFXCookie.prototype.setCookie = function (key, value) {
  125.     document.cookie = key + "=" + escape(value);
  126. }
  127.  
  128. WebFXCookie.prototype.getCookie = function (key) {
  129.     if (this.cookies) {
  130.         var start = this.cookies.indexOf(' ' + key + '=');
  131.         if (start == -1) { return null; }
  132.         var end = this.cookies.indexOf(";", start);
  133.         if (end == -1) { end = this.cookies.length; }
  134.         end -= start;
  135.         var cookie = this.cookies.substr(start,end);
  136.         return unescape(cookie.substr(cookie.indexOf('=') + 1, cookie.length - cookie.indexOf('=') + 1));
  137.     }
  138.     else { return null; }
  139. }
  140.  
  141. /*
  142.  * WebFXTreeAbstractNode class
  143.  */
  144.  
  145. function WebFXTreeAbstractNode(sText, sAction) {
  146.     this.childNodes  = [];
  147.     this.id     = webFXTreeHandler.getId();
  148.     this.text   = sText || webFXTreeConfig.defaultText;
  149.     this.action = sAction || webFXTreeConfig.defaultAction;
  150.     this._last  = false;
  151.     webFXTreeHandler.all[this.id] = this;
  152. }
  153.  
  154. /*
  155.  * To speed thing up if you're adding multiple nodes at once (after load)
  156.  * use the bNoIdent parameter to prevent automatic re-indentation and call
  157.  * the obj.ident() method manually once all nodes has been added.
  158.  */
  159.  
  160. WebFXTreeAbstractNode.prototype.add = function (node, bNoIdent) {
  161.     node.parentNode = this;
  162.     this.childNodes[this.childNodes.length] = node;
  163.     var root = this;
  164.     if (this.childNodes.length >= 2) {
  165.         this.childNodes[this.childNodes.length - 2]._last = false;
  166.     }
  167.     while (root.parentNode) { root = root.parentNode; }
  168.     if (root.rendered) {
  169.         if (this.childNodes.length >= 2) {
  170.             document.getElementById(this.childNodes[this.childNodes.length - 2].id + '-plus').src = ((this.childNodes[this.childNodes.length -2].folder)?((this.childNodes[this.childNodes.length -2].open)?webFXTreeConfig.tMinusIcon:webFXTreeConfig.tPlusIcon):webFXTreeConfig.tIcon);
  171.             this.childNodes[this.childNodes.length - 2].plusIcon = webFXTreeConfig.tPlusIcon;
  172.             this.childNodes[this.childNodes.length - 2].minusIcon = webFXTreeConfig.tMinusIcon;
  173.             this.childNodes[this.childNodes.length - 2]._last = false;
  174.         }
  175.         this._last = true;
  176.         var foo = this;
  177.         while (foo.parentNode) {
  178.             for (var i = 0; i < foo.parentNode.childNodes.length; i++) {
  179.                 if (foo.id == foo.parentNode.childNodes[i].id) { break; }
  180.             }
  181.             if (i == foo.parentNode.childNodes.length - 1) { foo.parentNode._last = true; }
  182.             else { foo.parentNode._last = false; }
  183.             foo = foo.parentNode;
  184.         }
  185.         webFXTreeHandler.insertHTMLBeforeEnd(document.getElementById(this.id + '-cont'), node.toString());
  186.         if ((!this.folder) && (!this.openIcon)) {
  187.             this.icon = webFXTreeConfig.folderIcon;
  188.             this.openIcon = webFXTreeConfig.openFolderIcon;
  189.         }
  190.         if (!this.folder) { this.folder = true; this.collapse(true); }
  191.         if (!bNoIdent) { this.indent(); }
  192.     }
  193.     return node;
  194. }
  195.  
  196. WebFXTreeAbstractNode.prototype.toggle = function() {
  197.     if (this.folder) {
  198.         if (this.open) { this.collapse(); }
  199.         else { this.expand(); }
  200. }    }
  201.  
  202. WebFXTreeAbstractNode.prototype.select = function() {
  203.     document.getElementById(this.id + '-anchor').focus();
  204. }
  205.  
  206. WebFXTreeAbstractNode.prototype.deSelect = function() {
  207.     document.getElementById(this.id + '-anchor').className = '';
  208.     webFXTreeHandler.selected = null;
  209. }
  210.  
  211. WebFXTreeAbstractNode.prototype.focus = function() {
  212.     if ((webFXTreeHandler.selected) && (webFXTreeHandler.selected != this)) { webFXTreeHandler.selected.deSelect(); }
  213.     webFXTreeHandler.selected = this;
  214.     if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) { document.getElementById(this.id + '-icon').src = this.openIcon; }
  215.     document.getElementById(this.id + '-anchor').className = 'selected';
  216.     document.getElementById(this.id + '-anchor').focus();
  217.     if (webFXTreeHandler.onSelect) { webFXTreeHandler.onSelect(this); }
  218. }
  219.  
  220. WebFXTreeAbstractNode.prototype.blur = function() {
  221.     if ((this.openIcon) && (webFXTreeHandler.behavior != 'classic')) { document.getElementById(this.id + '-icon').src = this.icon; }
  222.     document.getElementById(this.id + '-anchor').className = 'selected-inactive';
  223. }
  224.  
  225. WebFXTreeAbstractNode.prototype.doExpand = function() {
  226.     if (webFXTreeHandler.behavior == 'classic') { document.getElementById(this.id + '-icon').src = this.openIcon; }
  227.     if (this.childNodes.length) {  document.getElementById(this.id + '-cont').style.display = 'block'; }
  228.     this.open = true;
  229.     if (webFXTreeConfig.usePersistence) {
  230.         webFXTreeHandler.cookies.setCookie(this.id.substr(18,this.id.length - 18), '1');
  231. }    }
  232.  
  233. WebFXTreeAbstractNode.prototype.doCollapse = function() {
  234.     if (webFXTreeHandler.behavior == 'classic') { document.getElementById(this.id + '-icon').src = this.icon; }
  235.     if (this.childNodes.length) { document.getElementById(this.id + '-cont').style.display = 'none'; }
  236.     this.open = false;
  237.     if (webFXTreeConfig.usePersistence) {
  238.         webFXTreeHandler.cookies.setCookie(this.id.substr(18,this.id.length - 18), '0');
  239. }    }
  240.  
  241. WebFXTreeAbstractNode.prototype.expandAll = function() {
  242.     this.expandChildren();
  243.     if ((this.folder) && (!this.open)) { this.expand(); }
  244. }
  245.  
  246. WebFXTreeAbstractNode.prototype.expandChildren = function() {
  247.     for (var i = 0; i < this.childNodes.length; i++) {
  248.         this.childNodes[i].expandAll();
  249. } }
  250.  
  251. WebFXTreeAbstractNode.prototype.collapseAll = function() {
  252.     this.collapseChildren();
  253.     if ((this.folder) && (this.open)) { this.collapse(true); }
  254. }
  255.  
  256. WebFXTreeAbstractNode.prototype.collapseChildren = function() {
  257.     for (var i = 0; i < this.childNodes.length; i++) {
  258.         this.childNodes[i].collapseAll();
  259. } }
  260.  
  261. WebFXTreeAbstractNode.prototype.indent = function(lvl, del, last, level, nodesLeft) {
  262.     /*
  263.      * Since we only want to modify items one level below ourself,
  264.      * and since the rightmost indentation position is occupied by
  265.      * the plus icon we set this to -2
  266.      */
  267.     if (lvl == null) { lvl = -2; }
  268.     var state = 0;
  269.     for (var i = this.childNodes.length - 1; i >= 0 ; i--) {
  270.         state = this.childNodes[i].indent(lvl + 1, del, last, level);
  271.         if (state) { return; }
  272.     }
  273.     if (del) {
  274.         if ((level >= this._level) && (document.getElementById(this.id + '-plus'))) {
  275.             if (this.folder) {
  276.                 document.getElementById(this.id + '-plus').src = (this.open)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.lPlusIcon;
  277.                 this.plusIcon = webFXTreeConfig.lPlusIcon;
  278.                 this.minusIcon = webFXTreeConfig.lMinusIcon;
  279.             }
  280.             else if (nodesLeft) { document.getElementById(this.id + '-plus').src = webFXTreeConfig.lIcon; }
  281.             return 1;
  282.     }    }
  283.     var foo = document.getElementById(this.id + '-indent-' + lvl);
  284.     if (foo) {
  285.         if ((foo._last) || ((del) && (last))) { foo.src =  webFXTreeConfig.blankIcon; }
  286.         else { foo.src =  webFXTreeConfig.iIcon; }
  287.     }
  288.     return 0;
  289. }
  290.  
  291. /*
  292.  * WebFXTree class
  293.  */
  294.  
  295. function WebFXTree(sText, sAction, sBehavior, sIcon, sOpenIcon) {
  296.     this.base = WebFXTreeAbstractNode;
  297.     this.base(sText, sAction);
  298.     this.icon      = sIcon || webFXTreeConfig.rootIcon;
  299.     this.openIcon  = sOpenIcon || webFXTreeConfig.openRootIcon;
  300.     /* Defaults to open */
  301.     if (webFXTreeConfig.usePersistence) {
  302.         this.open  = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '0')?false:true;
  303.     } else { this.open  = true; }
  304.     this.folder    = true;
  305.     this.rendered  = false;
  306.     this.onSelect  = null;
  307.     if (!webFXTreeHandler.behavior) {  webFXTreeHandler.behavior = sBehavior || webFXTreeConfig.defaultBehavior; }
  308. }
  309.  
  310. WebFXTree.prototype = new WebFXTreeAbstractNode;
  311.  
  312. WebFXTree.prototype.setBehavior = function (sBehavior) {
  313.     webFXTreeHandler.behavior =  sBehavior;
  314. };
  315.  
  316. WebFXTree.prototype.getBehavior = function (sBehavior) {
  317.     return webFXTreeHandler.behavior;
  318. };
  319.  
  320. WebFXTree.prototype.getSelected = function() {
  321.     if (webFXTreeHandler.selected) { return webFXTreeHandler.selected; }
  322.     else { return null; }
  323. }
  324.  
  325. WebFXTree.prototype.remove = function() { }
  326.  
  327. WebFXTree.prototype.expand = function() {
  328.     this.doExpand();
  329. }
  330.  
  331. WebFXTree.prototype.collapse = function(b) {
  332.     if (!b) { this.focus(); }
  333.     this.doCollapse();
  334. }
  335.  
  336. WebFXTree.prototype.getFirst = function() {
  337.     return null;
  338. }
  339.  
  340. WebFXTree.prototype.getLast = function() {
  341.     return null;
  342. }
  343.  
  344. WebFXTree.prototype.getNextSibling = function() {
  345.     return null;
  346. }
  347.  
  348. WebFXTree.prototype.getPreviousSibling = function() {
  349.     return null;
  350. }
  351.  
  352. WebFXTree.prototype.keydown = function(key) {
  353.     if (key == 39) {
  354.         if (!this.open) { this.expand(); }
  355.         else if (this.childNodes.length) { this.childNodes[0].select(); }
  356.         return false;
  357.     }
  358.     if (key == 37) { this.collapse(); return false; }
  359.     if ((key == 40) && (this.open) && (this.childNodes.length)) { this.childNodes[0].select(); return false; }
  360.     return true;
  361. }
  362.  
  363. WebFXTree.prototype.toString = function() {
  364.     var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">" +
  365.         "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\">" +
  366.         "<a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\"" +
  367.         (this.target ? " target=\"" + this.target + "\"" : "") +
  368.         ">" + this.text + "</a></div>" +
  369.         "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
  370.     var sb = [];
  371.     for (var i = 0; i < this.childNodes.length; i++) {
  372.         sb[i] = this.childNodes[i].toString(i, this.childNodes.length);
  373.     }
  374.     this.rendered = true;
  375.     return str + sb.join("") + "</div>";
  376. };
  377.  
  378. /*
  379.  * WebFXTreeItem class
  380.  */
  381.  
  382. function WebFXTreeItem(sText, sAction, eParent, sIcon, sOpenIcon) {
  383.     this.base = WebFXTreeAbstractNode;
  384.     this.base(sText, sAction);
  385.     /* Defaults to close */
  386.     if (webFXTreeConfig.usePersistence) {
  387.         this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '1')?true:false;
  388.     } else { this.open = false; }
  389.     if (sIcon) { this.icon = sIcon; }
  390.     if (sOpenIcon) { this.openIcon = sOpenIcon; }
  391.     if (eParent) { eParent.add(this); }
  392. }
  393.  
  394. WebFXTreeItem.prototype = new WebFXTreeAbstractNode;
  395.  
  396. WebFXTreeItem.prototype.remove = function() {
  397.     var iconSrc = document.getElementById(this.id + '-plus').src;
  398.     var parentNode = this.parentNode;
  399.     var prevSibling = this.getPreviousSibling(true);
  400.     var nextSibling = this.getNextSibling(true);
  401.     var folder = this.parentNode.folder;
  402.     var last = ((nextSibling) && (nextSibling.parentNode) && (nextSibling.parentNode.id == parentNode.id))?false:true;
  403.     this.getPreviousSibling().focus();
  404.     this._remove();
  405.     if (parentNode.childNodes.length == 0) {
  406.         document.getElementById(parentNode.id + '-cont').style.display = 'none';
  407.         parentNode.doCollapse();
  408.         parentNode.folder = false;
  409.         parentNode.open = false;
  410.     }
  411.     if (!nextSibling || last) { parentNode.indent(null, true, last, this._level, parentNode.childNodes.length); }
  412.     if ((prevSibling == parentNode) && !(parentNode.childNodes.length)) {
  413.         prevSibling.folder = false;
  414.         prevSibling.open = false;
  415.         iconSrc = document.getElementById(prevSibling.id + '-plus').src;
  416.         iconSrc = iconSrc.replace('minus', '').replace('plus', '');
  417.         document.getElementById(prevSibling.id + '-plus').src = iconSrc;
  418.         document.getElementById(prevSibling.id + '-icon').src = webFXTreeConfig.fileIcon;
  419.     }
  420.     if (document.getElementById(prevSibling.id + '-plus')) {
  421.         if (parentNode == prevSibling.parentNode) {
  422.             iconSrc = iconSrc.replace('minus', '').replace('plus', '');
  423.             document.getElementById(prevSibling.id + '-plus').src = iconSrc;
  424. }    }    }
  425.  
  426. WebFXTreeItem.prototype._remove = function() {
  427.     for (var i = this.childNodes.length - 1; i >= 0; i--) {
  428.         this.childNodes[i]._remove();
  429.      }
  430.     for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  431.         if (this == this.parentNode.childNodes[i]) {
  432.             for (var j = i; j < this.parentNode.childNodes.length; j++) {
  433.                 this.parentNode.childNodes[j] = this.parentNode.childNodes[j+1];
  434.             }
  435.             this.parentNode.childNodes.length -= 1;
  436.             if (i + 1 == this.parentNode.childNodes.length) { this.parentNode._last = true; }
  437.             break;
  438.     }    }
  439.     webFXTreeHandler.all[this.id] = null;
  440.     var tmp = document.getElementById(this.id);
  441.     if (tmp) { tmp.parentNode.removeChild(tmp); }
  442.     tmp = document.getElementById(this.id + '-cont');
  443.     if (tmp) { tmp.parentNode.removeChild(tmp); }
  444. }
  445.  
  446. WebFXTreeItem.prototype.expand = function() {
  447.     this.doExpand();
  448.     document.getElementById(this.id + '-plus').src = this.minusIcon;
  449. }
  450.  
  451. WebFXTreeItem.prototype.collapse = function(b) {
  452.     if (!b) { this.focus(); }
  453.     this.doCollapse();
  454.     document.getElementById(this.id + '-plus').src = this.plusIcon;
  455. }
  456.  
  457. WebFXTreeItem.prototype.getFirst = function() {
  458.     return this.childNodes[0];
  459. }
  460.  
  461. WebFXTreeItem.prototype.getLast = function() {
  462.     if (this.childNodes[this.childNodes.length - 1].open) { return this.childNodes[this.childNodes.length - 1].getLast(); }
  463.     else { return this.childNodes[this.childNodes.length - 1]; }
  464. }
  465.  
  466. WebFXTreeItem.prototype.getNextSibling = function() {
  467.     for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  468.         if (this == this.parentNode.childNodes[i]) { break; }
  469.     }
  470.     if (++i == this.parentNode.childNodes.length) { return this.parentNode.getNextSibling(); }
  471.     else { return this.parentNode.childNodes[i]; }
  472. }
  473.  
  474. WebFXTreeItem.prototype.getPreviousSibling = function(b) {
  475.     for (var i = 0; i < this.parentNode.childNodes.length; i++) {
  476.         if (this == this.parentNode.childNodes[i]) { break; }
  477.     }
  478.     if (i == 0) { return this.parentNode; }
  479.     else {
  480.         if ((this.parentNode.childNodes[--i].open) || (b && this.parentNode.childNodes[i].folder)) { return this.parentNode.childNodes[i].getLast(); }
  481.         else { return this.parentNode.childNodes[i]; }
  482. } }
  483.  
  484. WebFXTreeItem.prototype.keydown = function(key) {
  485.     if ((key == 39) && (this.folder)) {
  486.         if (!this.open) { this.expand(); }
  487.         else { this.getFirst().select(); }
  488.         return false;
  489.     }
  490.     else if (key == 37) {
  491.         if (this.open) { this.collapse(); }
  492.         else { this.parentNode.select(); }
  493.         return false;
  494.     }
  495.     else if (key == 40) {
  496.         if (this.open) { this.getFirst().select(); }
  497.         else {
  498.             var sib = this.getNextSibling();
  499.             if (sib) { sib.select(); }
  500.         }
  501.         return false;
  502.     }
  503.     else if (key == 38) { this.getPreviousSibling().select(); return false; }
  504.     return true;
  505. }
  506.  
  507. WebFXTreeItem.prototype.toString = function (nItem, nItemCount) {
  508.     var foo = this.parentNode;
  509.     var indent = '';
  510.     if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
  511.     var i = 0;
  512.     while (foo.parentNode) {
  513.         foo = foo.parentNode;
  514.         indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?webFXTreeConfig.blankIcon:webFXTreeConfig.iIcon) + "\">" + indent;
  515.         i++;
  516.     }
  517.     this._level = i;
  518.     if (this.childNodes.length) { this.folder = 1; }
  519.     else { this.open = false; }
  520.     if ((this.folder) || (webFXTreeHandler.behavior != 'classic')) {
  521.         if (!this.icon) { this.icon = webFXTreeConfig.folderIcon; }
  522.         if (!this.openIcon) { this.openIcon = webFXTreeConfig.openFolderIcon; }
  523.     }
  524.     else if (!this.icon) { this.icon = webFXTreeConfig.fileIcon; }
  525.     var label = this.text.replace(/</g, '<').replace(/>/g, '>');
  526.     var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">" +
  527.         indent +
  528.         "<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon):((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon)):((this.parentNode._last)?webFXTreeConfig.lIcon:webFXTreeConfig.tIcon)) + "\" onclick=\"webFXTreeHandler.toggle(this);\">" +
  529.         "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\">" +
  530.         "<a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\"" +
  531.         (this.target ? " target=\"" + this.target + "\"" : "") +
  532.         ">" + label + "</a></div>" +
  533.         "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
  534.     var sb = [];
  535.     for (var i = 0; i < this.childNodes.length; i++) {
  536.         sb[i] = this.childNodes[i].toString(i,this.childNodes.length);
  537.     }
  538.     this.plusIcon = ((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon);
  539.     this.minusIcon = ((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon);
  540.     return str + sb.join("") + "</div>";
  541. }